#include "particlearea.h"
#include <QBoxLayout>
#include <QLabel>
#include <QPainter>
ParticleArea::ParticleArea(QWidget* parent):QWidget(parent)
{
    this->resize(10500,190);
    QLabel *label =new QLabel(this);
    label->setStyleSheet("QLabel{background-image:url(':resources/images/125.png') ;background-repeat:no-repeat;}");
    label->move(0,0);
    label->setFixedSize(this->width()*0.6, height()*0.47);

}
void ParticleArea::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    //QPixmap pixmap(":/resources/images/125.png");
    //painter.setRenderHint(QPainter::Antialiasing);
    //painter.drawPixmap(0, 0, this->width()*0.6, height()*0.45, pixmap);

    QPixmap pixmap1(":/resources/images/back.png");
    painter.drawPixmap(0, this->height()*0.5,this->width()*0.6, height()*0.45, pixmap1);

    QPixmap pixmap2(":/resources/images/unuserparticle.png");
    painter.drawPixmap(this->width()*0.01, this->height()*0.64,this->width()*0.025*(total - used), height()*0.137, pixmap2);

    for(int i=0;i<total -used;i++)
    {
        QBrush brush(QColor(60,177,211));
        painter.setBrush(brush);
        painter.setPen(Qt::NoPen);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.drawRoundedRect(this->width()*0.01+i*this->width()*0.025,this->height()*0.64,this->width()*0.015, height()*0.14,this->width()*0.05, height()*0.05);
       // painter.drawPixmap(this->width()*0.018,this->height()*0.64,this->width()*0.0286 *(i+1), height()*0.14,pixmap2);
    }
    for(int i=0;i<used;i++)
    {
        QBrush brush(QColor(75,94,108));
        painter.setBrush(brush);
        painter.setPen(Qt::NoPen);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.drawRoundedRect(this->width()*0+this->width()*0.025*(total - used)+this->width()*0.025*used-i*this->width()*0.026,this->height()*0.64,this->width()*0.015, height()*0.14,this->width()*0.05, height()*0.05);
       // painter.drawPixmap(this->width()*0.574-i*this->width()*0.029,this->height()*0.64,this->width()*0.015 *(i+1), height()*0.14,pixmap3);
    }
    QPixmap pixmap3(":/resources/images/userdpart.png");
    painter.drawPixmap(this->width()*0.01+this->width()*0.025*(total - used),this->height()*0.64,this->width()*0.025*used, height()*0.137, pixmap3);

    QFont font;
    font.setPointSize(24); // 设置字体大小
    font.setBold(true);  // 加粗
    font.setLetterSpacing(QFont::AbsoluteSpacing, -7);
    painter.setFont(font);
    painter.setPen(Qt::white);
    painter.drawText(this->width()*0.6,this->height()*0.82, "Total 20   Used");

    QFont font1;
    font1.setPointSize(24); // 设置字体大小
    font1.setBold(true);    // 加粗
    font1.setLetterSpacing(QFont::AbsoluteSpacing, -5);
    QColor textColor1(60, 177, 211);
    textColor1.setAlpha(255); // 设置透明度为完全不透明（255）
    painter.setPen(textColor1);
    painter.setFont(font1);
    painter.drawText(this->width()*0.7,this->height()*0.81, "/");

    QFont font2;
    font2.setPointSize(24); // 设置字体大小
    font2.setBold(true);    // 加粗
    font2.setLetterSpacing(QFont::AbsoluteSpacing, -5);
    painter.setFont(font2);
    QColor textColor2(255, 17, 21);
    textColor2.setAlpha(255); // 设置透明度为完全不透明（255）
    painter.setPen(textColor2);
    painter.drawText(this->width()*0.79,this->height()*0.82,QString::number(used));

}
void ParticleArea::addOne()
{
    used = used +1;
    this->update();
}

void ParticleArea::subOne()
{
    used = used -1;
    this->update();
}
